package com.training.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public class DensityUtils {
    public static int dp2px(Context context, float scale) {

        return (int) (scale * context.getResources().getDisplayMetrics().density + 0.5f);
    }

    public static int px2dp(Context context, float scale) {
        return (int) (scale / context.getResources().getDisplayMetrics().density + 0.5f);
    }

    public static int getDensityDpi(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        manager.getDefaultDisplay().getMetrics(displayMetrics);
        return displayMetrics.densityDpi;
    }
    public static float getScaledDensity(Context context) {
        DisplayMetrics displayMetrics =new  DisplayMetrics();
        WindowManager manager= (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        manager.getDefaultDisplay().getMetrics(displayMetrics);
        return displayMetrics.scaledDensity;
    }
}
